package com.pft.web.view.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.EditText;

import com.pft.web.R;
import com.pft.web.WebJumpManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity
        extends AppCompatActivity {
    @BindView(R.id.edit_view)
    EditText edtContent;
    SharedPreferences sharedPreferences;

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        sharedPreferences = getSharedPreferences("user", 0);
        String url = this.sharedPreferences.getString("url", "");
        if (!TextUtils.isEmpty(url)) {
            WebJumpManager.startCommonWebView(this, url);
            finish();
            return;
        }
        this.edtContent.setText("");
    }

    @OnClick({R.id.btn_save})
    public void onViewClicked() {
        String str = this.edtContent.getText().toString();
        if (TextUtils.isEmpty(str)) {
            return;
        }
        this.sharedPreferences.edit().putString("url", str).commit();
        WebJumpManager.startCommonWebView(this, str);
        finish();
    }
}
